var page = sm("do_Page");
var app = sm("do_App");
var nf = sm("do_Notification");
var hashdata = mm("do_HashData");
var root = ui("$");
var http = require("helper/http");
var mallUrl = require("url/mall");
var helperOpen = require("helper/open");
var global = deviceone.sm("do_Global");

var shopId = null;
var shopAddress = null;
var shopHomeNumNew = "";
var jsonData = {};
//获取上一个页面传入的参数
page.on("loaded", function(){
	var params = page.getData();
	shopId = params.id;
	shopAddress = params.address;
});

//返回键
page.on("back", function() {
    app.closePage();
});

var headerAout = ui("headerAout");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
var header = ui("header");
ui(addheader + ".labelTitle").text = "修改店铺地址";
//左上角-返回
var headerLeft = ui(addheader+".headerLeft");
headerLeft.on("touch", function() {
    app.closePage();
});

//保存
var headerRight = ui(addheader+".headerRight");
var headerRight_lableNext = ui(addheader+".labelNext");
headerRight_lableNext.text = "保存";
headerRight_lableNext.visible = true;
headerRight.on("touch", function() {
	page.hideKeyboard();
	submit();
});

var linearLayout_main = ui("do_LinearLayout_main");
/** -------------------add UI start ---------------------------**/
/*门牌号*/
var addtxtHome = linearLayout_main.add("txtHome", "source://view/reuse/form/mutiInput.ui",0,0);
var txtHome = ui("txtHome");
txtHome.bindData(hashdata);
hashdata.addData({
    "textTitle" : "门牌号",
    "hint":'请填写您的门牌号'
});
txtHome.refreshData();
var txtHomeText = ui(addtxtHome+".textInput");

var addtxtCommunity = linearLayout_main.add("txtCommunity", "source://view/reuse/form/mutiLabel.ui",0,0);
var txtCommunity = ui("txtCommunity");
txtCommunity.bindData(hashdata);
hashdata.addData({
    "labelTitle" : "社区",
    "labelText":'',
    "labelTipsVisible":false,
    "labelTips":""
});
txtCommunity.refreshData();
txtCommunity.on("touch","",300,function(){
	page.hideKeyboard();
	global.setMemory("communityAddrCount", 0);
	helperOpen.open("source://view/area/selectCommunityAddr.ui",{});
});
var txtCommunityText = ui(addtxtCommunity+".labelText");
var addLine = linearLayout_main.add("line", "source://view/reuse/form/line.ui",0,0);
ui("line").refreshData();
/** -------------------add UI end ---------------------------**/
page.on("result", function(data) {
	if (data.fromPage && data.fromPage == 'selectCommunityAddr') {
		txtCommunityText.text = data.address;
		jsonData.communityId = data.communityId;
		jsonData.communityAddrId = data.addrId;
	}
});
function submit(){
	jsonData.id = shopId;
	jsonData.homeNum = txtHomeText.text;
	http.post(mallUrl.url.shop.updateAddress, jsonData, function(data) {
		app.fire("fireShopUpdate",{"address":data.mallShop.address});
		app.closePage();
	});
};